package org.qloudgen.txn.dilithium.cluster.operator;

import org.qloudgen.txn.dilithium.cluster.beans.Cluster;
import org.qloudgen.txn.dilithium.cluster.common.CommonValues;
import org.qloudgen.txn.dilithium.cluster.common.ShellExec;
import org.qloudgen.txn.dilithium.cluster.database.ClusterImpl;

public class ClusterOperatorImpl extends AbstractClusterOperator{

	public ClusterOperatorImpl(Cluster cluster, String operatorType) {
		super(cluster, operatorType);
	}

	@Override
	public int start(Cluster cluster) {
		
		int ret = ShellExec.clusterOperator(cluster, this.getOperatorType(),null,null);
		if (ret != 0 ) return ret;
		
		cluster.setClusterStatus(CommonValues.STATUS_ON);
		ClusterImpl.updateClusterStatus(cluster);
		return ret;
		
	}

	@Override
	public int stop(Cluster cluster){
		
		int ret = ShellExec.clusterOperator(cluster, this.getOperatorType(),null,null);
		if (ret != 0 ) return ret;
		
		cluster.setClusterStatus(CommonValues.STATUS_OFF);
		ClusterImpl.updateClusterStatus(cluster);
		return ret;
	}

	@Override
	public int delete(int clusterID) {
		
		ClusterImpl.deleteClusterID(clusterID);
		return 0;
	}

}
